import {observable,action,computed} from 'mobx';
import { message} from 'antd';
import * as goalDetail from '../../apis/goal/goalDetail';
import * as goalCommonAPI from '../../apis/goal/goalCommon'
import {WeaLocaleProvider} from 'ecCom';
const toJS = mobx.toJS;
const getLabel = WeaLocaleProvider.getLabel;
export default class GoalCommonStore {

    @observable createvisable = false; //是否打开新建弹出层
    @observable isFocusFeedBack = false; //反馈信息是否聚焦
    @observable condtype = "1";  //默认我的目标
    @observable orgCardList = []; //组织卡片
    @observable typeId = ""; //目标类型 1公司目标 2分部目标 3部门目标
    @observable orgId = ""; //组织id
    @observable orgtitle = "";
    @observable currentOrgId  = "0";
    @observable showImport = false; //目标导入
    @observable showExport = false; //目标导出
    @observable isOrgGoal = false //是否为组织目标

    iconArray =  {
        'goalids':"icon-portal-ModelingEngine","taskids":"icon-coms-currency-Task",
        "docids":"icon-portal-doc","wfids":"icon-coms-Workflow-o","crmids":"icon-portal-crm",
        "projectids":"icon-coms-project","fileids":"icon-coms-link"
    }

    @action
    setIsFocusFeedBack = (data) =>{
        this.isFocusFeedBack = data;
    }

    @action
    setCreatevisable = (data) =>{
        this.createvisable = data;
    }

    @action
    setCondtype = (data) =>{
        this.condtype = data;
        this.setIsOrgGoal(data);
    }

    @action
    setTypeId = (data) =>{
        this.typeId = data;
    } 

    @action
    setOrgId = (data) =>{
        this.orgId = data;
    }

    @action
    setOrgtitle = (data) =>{
        this.orgtitle = data;
    }

    @action
    setShowImport = (data) =>{
        this.showImport = data;
    }

    @action
    setShowExport = (data) =>{
        this.showExport = data;
    }

   
    @action
    setOrgData = (condtype,typeId,orgId) =>{
        this.condtype = condtype;
        this.typeId = typeId;
        this.orgId = orgId;
        this.setIsOrgGoal(condtype);
    }

    @action
    editStatus = (params) => {  //编辑列表状态（删除）
        goalDetail.editStatus(params).then(action(res=>{
            if(res.status){
                if (typeof params.doback === "function") {
                    if(params.status == '4'){
                         params.doback(params.goalId);
                         message.success(getLabel(20461,'删除成功'));
                         return;
                    } 
                }
            }else if(!res.api_status){
                message.error(res.msg || getLabel('25009','失败'));
            }
        }));
    }

    @action
    setIsOrgGoal = (condtype) =>{
        if(condtype == 2 || condtype == 8 || condtype == 9){
            this.isOrgGoal = true;
        }else{
            this.isOrgGoal = false;
        }
    }

}